package com.xueqiu.movieplaymanagersystem.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author xueqiu
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Value("${adminAddSortURL}")
    private String adminAddSortURL ;
    @Value("${adminAddTagURL}")
    private String adminAddTagURL ;
    @Value("${adminBlogTypeURL}")
    private String adminBlogTypeURL ;
    @Value("${adminBlogTagURL}")
    private String adminBlogTagURL ;
    @Value("${adminEditSortURL}")
    private String adminEditSortURL ;
    @Value("${adminEditTagURL}")
    private String adminEditTagURL ;
    @Value("${adminLoginHTML}")
    private String adminLoginHTML ;
    @Value("${adminBlogVisitHTML}")
    private String adminBlogVisitHTML ;
    /*@Value("${adminAddSortURLForward}")
    private String adminAddSortURLForward ;
    @Value("${adminAddTagURLForward}")
    private String adminAddTagURLForward ;
    @Value("${adminBlogTypeURLForward}")
    private String adminBlogTypeURLForward ;
    @Value("${adminBlogTagURLForward}")
    private String adminBlogTagURLForward ;
    @Value("${adminEditSortURLForward}")
    private String adminEditSortURLForward ;
    @Value("${adminEditTagURLForward}")
    private String adminEditTagURLForward ;
    @Value("${adminLoginHTMLForward}")
    private String adminLoginHTMLForward ;
    @Value("${adminBlogVisitHTMLForward}")
    private String adminBlogVisitHTMLForward ;*/

    /**
     * 用来做路由控制，控制页面的转发
     *
     * @param registry 注册表
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController(adminAddSortURL).setViewName("admin/blog/addSort");
        registry.addViewController(adminAddTagURL).setViewName("admin/blog/addTag");
        registry.addViewController(adminBlogTypeURL).setViewName("admin/blog/blogTypes");
        registry.addViewController(adminBlogTagURL).setViewName("admin/blog/blogTags");
        registry.addViewController(adminEditSortURL).setViewName("admin/blog/editType");
        registry.addViewController(adminEditTagURL).setViewName("admin/blog/editTag");
        registry.addViewController(adminLoginHTML).setViewName("admin/user/login");
        registry.addViewController(adminBlogVisitHTML).setViewName("admin/blog/blogVisit");
        /*registry.addViewController(adminAddSortURL).setViewName(adminAddSortURLForward);
        registry.addViewController(adminAddTagURL).setViewName(adminAddTagURLForward);
        registry.addViewController(adminBlogTypeURL).setViewName(adminBlogTypeURLForward);
        registry.addViewController(adminBlogTagURL).setViewName(adminBlogTagURLForward);
        registry.addViewController(adminEditSortURL).setViewName(adminEditSortURLForward);
        registry.addViewController(adminEditTagURL).setViewName(adminEditTagURLForward);
        registry.addViewController(adminLoginHTML).setViewName(adminLoginHTMLForward);
        registry.addViewController(adminBlogVisitHTML).setViewName(adminBlogVisitHTMLForward);*/
        /*registry.addViewController("/admin/addSort").setViewName("admin/blog/addSort");
        registry.addViewController("/admin/addTag").setViewName("admin/blog/addTag");
        registry.addViewController("/admin/blogType").setViewName("admin/blog/blogTypes");
        registry.addViewController("/admin/blogTag").setViewName("admin/blog/blogTags");
        registry.addViewController("/admin/editSort").setViewName("admin/blog/editType");
        registry.addViewController("/admin/editTag").setViewName("admin/blog/editTag");
        registry.addViewController("/admin/login.html").setViewName("admin/user/login");
        registry.addViewController("/admin/blogVisit.html").setViewName("admin/blog/blogVisit");*/
    }

    /**
     * 注册拦截器
     *
     * @param registry 注册表
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/admin/**")
                .excludePathPatterns("/static/**", "/usr/image/**");
        registry.addInterceptor(new VisitInterceptor())
                .addPathPatterns("/", "/index.html")
                .excludePathPatterns("/static/**", "/usr/image/**");
    }
    /*
    这段代码是在配置一个 Spring MVC 的拦截器 `IndexInterceptor`，并指定其应用和排除的路径模式。它是 `WebMvcConfigurer` 接口中 `addInterceptors` 方法的一部分。具体含义如下：
    1. **`registry.addInterceptor(new IndexInterceptor())`**:
       - 向 Spring MVC 注册一个拦截器实例 `IndexInterceptor`。
    2. **`.addPathPatterns("/", "/index.html")`**:
       - 指定拦截器应拦截的请求路径模式。在这里，它会拦截根路径 `/` 和 `/index.html` 的请求。
    3. **`.excludePathPatterns("/static/**", "/usr/image/**")`**:
       - 指定拦截器应排除的请求路径模式。在这里，任何以 `/static/` 和 `/usr/image/` 开头的请求路径都将被排除，不会被拦截器处理。
    通过这种配置，你可以灵活地控制拦截器的应用范围，确保它只在需要的请求路径上生效。
     */
}
